@section('content')
<div class="am-cf am-padding">
   <div class="am-fl am-cf">
      <strong class="am-text-primary am-text-lg">用户列表</strong>
   </div>
</div>
	<div class="am-g">
      <div class="am-u-md-12">
      	<form class="am-form-inline" role="form" style="text-align: right;" >
		  <div class="am-form-group">
		    <input type="text" name="name" class="am-form-field" placeholder="名称" >
		  </div>
		  <div class="am-form-group">
		  	 <input type="text" name="mobile" class="am-form-field" placeholder="手机">
		  </div>
		  <div class="am-form-group">
		  	 <input type="text" name="email" class="am-form-field" placeholder="Email">
		  </div>
		  <button type="submit" class="am-btn am-btn-default">查询</button>
		</form>
      </div>
    </div>
    <div class="am-g">
      <div class="am-u-sm-12">
          <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
              <tr>
                <th>ID</th>
                <th>名称</th>
                <th>邮箱</th>
                <th>电话</th>
                  <th>注册时间</th>
                <th>操作</th>
              </tr>
          </thead>
          <tbody>
          	@foreach ($users as $user)
            <tr data-id="{{$user->id}}"  data-name='{{$user->name}}'>
              <td>{{$user->id}}</td>
              <td>
              	<a href="{{URL::route('user.detail',$user->id)}}">{{$user->name}}</a>
              </td>
              <td>{{$user->email}}</td>
              <td>{{$user->mobile}}</td>
                <td>{{$user->created_at}}</td>
              <td>
                <div class="am-btn-toolbar">
                  <div class="am-btn-group am-btn-group-xs">
                  	<button class="am-btn am-btn-default am-btn-xs delete-product am-text-secondary"
                  		data-active="{{empty($user->active) ? true:false}}"
                    	data-am-loading="{loadingText: '执行中...'}">
                    	@if (!empty($user->active))
						<span class="am-icon-toggle-on"></span> 已激活
						@else
						  <span class="am-icon-toggle-off"></span> 未激活
						@endif
                    </button>
                  </div>
                </div>
              </td>
            </tr>
            @endforeach
          </tbody>
        </table>
        <div class="am-cf">
		  <div class="am-fr">
		  	<!-- 分页列表 -->
		  	{{$users->appends($search)->links("admin.slider")}}
		  </div>
		</div>
      </div>
    </div>
@stop

@section('script')

<script type="text/javascript">
$(function () {
	$(".delete-product").on("click",function(){
		var $btn = $(this);
		var $tr = $(this).closest("tr");
		$.post("{{URL::route('user.toggle')}}",$tr.data(),function(data){
	       	  $btn.button('reset');
	  		  if (data.success){
		  		 var active = $btn.data('active');
			  	 $btn.html(active ? "<span class='am-icon-toggle-on'></span>已激活" : "<span class='am-icon-toggle-off'></span>未激活");
				 $btn.data('active',!active);
	  		  } else {
		  		alert("错误");
			  }
		});
	});
});
</script>
@stop
